<template>
	<view class="charts-box">
		<u-subsection :list="list" :current="current" @change="sectionChange" mode="subsection"
			activeColor="#2997ff"></u-subsection>
		<view style="text-align: center; padding: 10rpx 20rpx; display: flex;justify-content: space-between;">
			<text style="font-size: 32rpx; color: #333; font-weight: bold;">成交客户行业分布分析</text>
			<u-icon name="more-dot-fill" color="#2979ff" size="28"></u-icon>
		</view>
		<qiun-data-charts type="line" :opts="opts" :chartData="chartData" />
	</view>
</template>

<script>
	export default {
		data() {
			return {
				list: ['存款', '贷款', '保险', '贵金属'],
				current: 0,

				chartData: {},
				//您可以通过修改 config-ucharts.js 文件中下标为 ['mount'] 的节点来配置全局默认参数，如都是默认参数，此处可以不传 opts 。实际应用过程中 opts 只需传入与全局默认参数中不一致的【某一个属性】即可实现同类型的图表显示不同的样式，达到页面简洁的需求。
				opts: {
					color: ["#1890FF", "#91CB74", "#FAC858", "#EE6666", "#73C0DE", "#3CA272", "#FC8452", "#9A60B4",
						"#ea7ccc"
					],
					padding: [15, 15, 0, 5],
					enableScroll: false,
					legend: {},
					xAxis: {
						disabled: true

					},
					yAxis: {

						data: [{
							min: 0
						}]
					},
					extra: {
						mount: {
							type: "bar",
							widthRatio: 0.3,
							barBorderCircle: true,
							linearType: "custom",
							seriesGap: 20,


						}
					}
				}
			};
		},
		created() {
			this.getServerData();
		},
		methods: {
			sectionChange(index) {
				this.current = index;
				this.getServerData(index)
			},

			getServerData(index) {
				//模拟从服务器获取数据时的延时
				let data = [{
					"name": "农业企业",
					"value": 82
				}, {
					"name": "制造企业",
					"value": 63
				}, {
					"name": "服务企业",
					"value": 86
				}, {
					"name": "事业单位",
					"value": 65
				}, {
					"name": "机关单位",
					"value": 79
				}, {
					"name": "部队",
					"value": 12
				}, {
					"name": "其他",
					"value": 51
				}]
				switch (index) {
					case 1:
						data = [{
							"name": "事业单位",
							"value": 65
						}, {
							"name": "机关单位",
							"value": 79
						}, {
							"name": "部队",
							"value": 12
						}, {
							"name": "其他",
							"value": 51
						}]
						break;
					case 2:
						data = [{
							"name": "农业企业",
							"value": 50
						}, {
							"name": "机关单位",
							"value": 80
						}, {
							"name": "部队",
							"value": 12
						}, {
							"name": "其他",
							"value": 51
						}]
						break;
					case 3:
						data = [{
							"name": "农业企业",
							"value": 12
						}, {
							"name": "制造企业",
							"value": 22
						}, {
							"name": "服务企业",
							"value": 50
						}, {
							"name": "部队",
							"value": 40
						}, {
							"name": "其他",
							"value": 30
						}]
						break;
					default:
						break;
				}
				setTimeout(() => {

					let res = {
						series: [{
							data: data
						}]
					};
					this.chartData = JSON.parse(JSON.stringify(res));
				}, 500);
			},
		}
	};
</script>

<style scoped>
	/* 请根据实际需求修改父元素尺寸，组件自动识别宽高 */
	.charts-box {
		width: 100%;
		padding: 24rpx;
		box-sizing: border-box;
		/* height: 300px; */
		background-color: #fff;
		margin-bottom: 24rpx;
	}
</style>